<%
class cls_Pub
	'是否为空
	public Function isNul(str)
		if isnull(str) or str=""  then isNul=true else isNul=false
	End Function
	  '判断是否不为空值
	  Public Function Has(ByVal s)
		Has = Not isNul(s)
	  End Function
	'是否为数字
	public Function isNum(str)
		if not isNul(str) then  isNum=isnumeric(str) else isNum=false
	End Function

	'是否为URL
	public Function isUrl(str)
		isUrl=false
		if not isNul(str) and left(str,7)="http://" then isUrl=true 
	End Function
	

	'iif 判断
	public Function IIF(ByVal s, ByVal T, ByVal F)
		If s Then
			IIF = T
		Else
			IIF = F
		End If
	End Function
	'路径前后加'/'
	public Function xPath(ByVal p)
		p = IIF(Left(p,1)= "/", p, "/" & p)
		p = IIF(Right(p,1)="/", p, p & "/")
		xPath = p
	End Function
	'输出
	public Sub echo(str)
		response.write(str)
		response.Flush()
	End Sub
	'调试
	public Sub debug(str)
		if ac.debug then
			response.write(str)
			response.Flush()
		end if
	End Sub
	
	'判断字符串中是否包含某字符串（忽略大小写）
	Public Function IsIn(s1, s2)
		If Has(s2) Then
		  IsIn = InStr(1, s1, s2, 1)>0
		  else
		  IsIn=false
		End If

	End Function
	
  '检查字符串是否属于逗号隔开的字符串序列中的一个
  '返回：Boolean值
  '说明：If Easp.Str.IsInList("A,B,C", str) Then
  '     等同于下面的语句并且忽略大小写：
  '     If str = "A" Or str = "B" Or str = "C" Then
  Public Function IsInList(ByVal s, ByVal str)
    Dim s1, s2
    If Has(str) Then
      s1 = IIF(Left(s,1)=",", s, "," & s)
      s1 = IIF(Right(s1,1)=",", s1, s1 & ",")
      s2 = IIF(Left(str,1)=",", str, "," & str)
      s2 = IIF(Right(s2,1)=",", s2, s2 & ",")
      IsInList = IsIn(s1, s2)
    End If
  End Function
	
	'转换时间
	't : 要转换的时间  weekday
	'ftype: 格式 Eg yyyy-MM-dd HH:mm:ss tt  w 
	public Function formatDate(Byval t,Byval ftype)
		dim y, m, d, h, mi, s,tt
		formatDate=""
		If not IsDate(t) Then  Exit Function
		
		formatDate=ftype
		y=cstr(year(t))
			if IsIn(formatDate,"yyyy")	then formatDate=replace(formatDate,"yyyy",y)
			if IsIn(formatDate,"yy")		then formatDate=replace(formatDate,"yy",right(y,2))
			if IsIn(formatDate,"y")		then formatDate=replace(formatDate,"y",right(y,2))
		m=cstr(month(t))
			if not IsIn(formatDate,"MM") and 	IsIn(formatDate,"M") then
				formatDate=replace(formatDate,"M",m)
			end if
		If len(m)=1 Then m="0" & m
			if IsIn(formatDate,"MM")		then formatDate=replace(formatDate,"MM",m)
		
		
		d=cstr(day(t))
			if not IsIn(formatDate,"dd") and 	IsIn(formatDate,"d") then
				formatDate=replace(formatDate,"d",d)
			end if
		If len(d)=1 Then d="0" & d
			if IsIn(formatDate,"dd")		then formatDate=replace(formatDate,"dd",d)
		h=cstr(hour(t))
			if not IsIn(formatDate,"HH") and 	IsIn(formatDate,"H") then
				formatDate=replace(formatDate,"H",h)
			end if
		If len(h)=1 Then h="0" & h
			if IsIn(formatDate,"HH")		then formatDate=replace(formatDate,"HH",h)
		h = hour(t): tt=IIf(h>12,"pm","am"):h=h-12 : h=cstr(h)
			if IsIn(formatDate,"tt")		then formatDate=replace(formatDate,"tt",ac.lang.val("date."&tt))
			
			if not IsIn(formatDate,"h") and 	IsIn(formatDate,"h") then
				formatDate=replace(formatDate,"h",h)
			end if
		If len(h)=1 Then h="0" & h
			if IsIn(formatDate,"hh")		then formatDate=replace(formatDate,"hh",h)
			
		mi = cstr(minute(t))
			if not IsIn(formatDate,"mm") and 	IsIn(formatDate,"m") then
				formatDate=replace(formatDate,"m",mi)
			end if
		If len(mi)=1 Then mi="0" & mi
			if IsIn(formatDate,"mm")		then formatDate=replace(formatDate,"mm",mi)
		s = cstr(second(t))
			if not IsIn(formatDate,"ss") and 	IsIn(formatDate,"s") then
				formatDate=replace(formatDate,"s",s)
			end if
		If len(s)=1 Then s="0" & s
			if IsIn(formatDate,"ss")		then formatDate=replace(formatDate,"ss",s)
		if IsIn(formatDate,"www") then formatDate=replace(formatDate,"www",ac.lang.val("date.week."&weekday(t)))
	End Function	
	
	
  '正则替换
  Public Function Replace(ByVal s, ByVal rule, ByVal replaceWith)
    Replace = ac_Replace(s, rule, replaceWith, False)
  End Function
  '正则替换原型
  Private Function ac_Replace(ByVal s, ByVal rule, Byval result, ByVal isMultiLine)
    Dim o_regexp
    If Has(s) Then
      Set o_regexp = New Regexp
      o_regexp.Global = True
      o_regexp.IgnoreCase = True
      If isMultiLine Then o_regexp.Multiline = True
      o_regexp.Pattern = rule
      s = o_regexp.Replace(s,result)
      Set o_regexp = Nothing
    End If
    ac_Replace = s
  End Function
  '正则匹配原型
  Private Function ac_Test(ByVal s, ByVal p)
    Dim o_regexp
    If IsNul(s) Then ac_Test = False : Exit Function
    Set o_regexp = New Regexp
    o_regexp.Global = True
    o_regexp.IgnoreCase = True
    o_regexp.Pattern = p
    ac_Test = o_regexp.Test(CStr(s))
    Set o_regexp = Nothing
  End Function

  '正则表达式特殊字符转义
  Public Function RegexpEncode(ByVal s)
    Dim re,i
    re = Split("\,$,(,),*,+,.,[,?,^,{,|",",")
    For i = 0 To Ubound(re)
      s = o_re.Re(s, re(i), "\" & re(i))
    Next
    RegexpEncode = s
  End Function

end class

'重写VBS内部函数
Class EasyASP_sOriginal
  Public Function Re(ByVal s, ByVal find, ByVal replacewith)
    Re = Replace(s, find, replaceWith)
  End Function
  Public Function ReCase(ByVal s, ByVal find, ByVal replaceWith)
    ReCase = Replace(s, find, replaceWith, 1, -1, 1)
  End Function
  Public Function ReFull(ByVal s, ByVal find, ByVal replaceWith, ByVal start, ByVal count, ByVal compare)
    ReFull = Replace(s, find, replaceWith, start, count, compare)
  End Function
  Public Function Instr_(ByVal s1, ByVal s2)
    Instr_ = Instr(s1, s2)
  End Function
  Public Function Instr__(ByVal s1, ByVal s2, ByVal start, ByVal compare)
    Instr__ = Instr(start, s1, s2, compare)
  End Function
  Public Function InStrRev_(ByVal s1, ByVal s2)
    InStrRev_ = InStrRev(s1, s2)
  End Function
  Public Function InStrRev__(ByVal s1, ByVal s2, ByVal start, ByVal compare)
    InStrRev__ = InStrRev(s1, s2, start, compare)
  End Function
  Public Function LCase_(ByVal s)
    LCase_ = LCase(s)
  End Function
  Public Function Left_(ByVal s, ByVal length)
    Left_ = Left(s, length)
  End Function
  Public Function Len_(ByVal s)
    Len_ = Len(s)
  End Function
  Public Function LTrim_(ByVal s)
    LTrim_ = LTrim(s)
  End Function
  Public Function RTrim_(ByVal s)
    RTrim_ = RTrim(s)
  End Function
  Public Function Trim_(ByVal s)
    Trim_ = Trim(s)
  End Function
  Public Function Mid_(ByVal s, ByVal start)
    Mid_ = Mid(s, start)
  End Function
  Public Function Mid__(ByVal s, ByVal start, ByVal length)
    Mid__ = Mid(s, start, length)
  End Function
  Public Function Right_(ByVal s, ByVal length)
    Right_ = Right(s, length)
  End Function
  Public Function StrComp_(ByVal s1, ByVal s2)
    StrComp_ = StrComp(s1, s2)
  End Function
  Public Function StrComp__(ByVal s1, ByVal s2, ByVal compare)
    StrComp__ = StrComp(s1, s2, compare)
  End Function
  Public Function StrReverse_(ByVal s)
    StrReverse_ = StrReverse(s)
  End Function
  Public Function Split_(ByVal s, ByVal separator)
    Split_ = Split(s, separator)
  End Function
  Public Function UCase_(ByVal s)
    UCase_ = UCase(s)
  End Function

 End Class
%>



<script language="JScript" runAt="server">
	function myEncodeURIComponent(sStr){ 
		return encodeURIComponent(sStr); 
	} 

	var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	var base64DecodeChars = new Array(
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
	-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
	52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
	-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
	15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
	-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
	41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);

	function base64encode(str) {
		var out, i, len;
		var c1, c2, c3;

		len = str.length;
		i = 0;
		out = "";
		while(i < len) {
			c1 = str.charCodeAt(i++) & 0xff;
			if(i == len)
			{
				out += base64EncodeChars.charAt(c1 >> 2);
				out += base64EncodeChars.charAt((c1 & 0x3) << 4);
				out += "==";
				break;
			}
			c2 = str.charCodeAt(i++);
			if(i == len)
			{
				out += base64EncodeChars.charAt(c1 >> 2);
				out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
				out += base64EncodeChars.charAt((c2 & 0xF) << 2);
				out += "=";
				break;
			}
			c3 = str.charCodeAt(i++);
			out += base64EncodeChars.charAt(c1 >> 2);
			out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
			out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
			out += base64EncodeChars.charAt(c3 & 0x3F);
		}
		return out;
	}

	function base64decode(str) {
		var c1, c2, c3, c4;
		var i, len, out;

		len = str.length;
		i = 0;
		out = "";
		while(i < len) {
			/* c1 */
			do {
				c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
			} while(i < len && c1 == -1);
			if(c1 == -1)
			break;

			/* c2 */
			do {
				c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
			} while(i < len && c2 == -1);
			if(c2 == -1)
			break;

			out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));

			/* c3 */
			do {
				c3 = str.charCodeAt(i++) & 0xff;
				if(c3 == 61)
					return out;
				c3 = base64DecodeChars[c3];
			} while(i < len && c3 == -1);
			if(c3 == -1)
			break;

			out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));

			/* c4 */
			do {
				c4 = str.charCodeAt(i++) & 0xff;
				if(c4 == 61)
				return out;
				c4 = base64DecodeChars[c4];
			} while(i < len && c4 == -1);
			if(c4 == -1)
			break;
			out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
		}
		return out;
	}

	function Base64DecodeText(Base64Str){ 
		var xml_dom = new ActiveXObject("MSXML2.DOMDocument"); 
		var ado_stream = new ActiveXObject("ADODB.Stream"); 
		var tmpNode = xml_dom.createElement("tmpNode"); 
		tmpNode.dataType = "bin.base64"; 
		tmpNode.text = Base64Str; 

		ado_stream.Charset = "gb2312"; 
		ado_stream.Type = 1; // 1=adTypeBinary 2=adTypeText 
		ado_stream.Open(); 
		ado_stream.Write(tmpNode.nodeTypedValue); 
		ado_stream.Position = 0; 
		ado_stream.Type = 2; // 1=adTypeBinary 2=adTypeText 
		var str = ado_stream.ReadText(-1); // -1=adReadAll 
		ado_stream.Close(); 

		return str; 
	}

</script>
	